package com.dhy.cp;

import com.google.auto.service.AutoService;

import java.util.Set;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;

import static com.dhy.cp.ComponentProcessorKt.OPTION_ANNOTATION;
import static com.dhy.cp.ComponentProcessorKt.OPTION_JAVA_DIR;
import static com.dhy.cp.ComponentProcessorKt.OPTION_MODULE_NAME;

/**
 * 继承AbstractProcessor的类必需是JAVA类，KT的不能运行。但其中可以引用KT的类。
 */
@AutoService(Processor.class)
@SupportedOptions({OPTION_MODULE_NAME, OPTION_JAVA_DIR, OPTION_ANNOTATION})
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class ComponentProcessorInJava extends AbstractProcessor {
    private final ComponentProcessor processor = new ComponentProcessor();

    @Override
    public synchronized void init(ProcessingEnvironment processingEnv) {
        super.init(processingEnv);
        processor.init(processingEnv);
    }

    @Override
    public Set<String> getSupportedAnnotationTypes() {
        return processor.getSupportedAnnotationTypes();
    }

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        return processor.process(annotations, roundEnv);
    }
}
